# 使用xiaobias-lw/openjdk:21-jdk-alpine基础镜像
FROM crpi-towvl3w1m5u542tl.cn-guangzhou.personal.cr.aliyuncs.com/xiaobias-lw/openjdk:21-jdk-alpine

# 维护者信息
LABEL maintainer="197772517@qq.com"

ARG user=root
ARG group=root
ARG uid=0
ARG gid=0
ARG http_port=8080
ARG agent_port=50000
ARG REF=/usr/share/jenkins/ref

# 设置环境变量
ENV JENKINS_HOME=/var/jenkins_home
ENV JENKINS_VERSION=2.522
ENV JENKINS_WAR=/var/jenkins_home/jenkins.war
# 修复部分汉化问题
ENV LANG=en_US.UTF-8



# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum
# see https://github.com/docker/docker/issues/8331
ADD ./war/target/jenkins.war $JENKINS_WAR

# Jenkins是运行用户' Jenkins '， uid = 1000
# 将提前下载好的Jenkins WAR包添加到镜像中
#确保您使用相同的uid
RUN mkdir -p ${JENKINS_HOME} \
  && chown ${uid}:${gid} ${JENKINS_HOME}

# 安装所需的软件包 maven git ssh
RUN apk add --no-cache \
        maven \
        git \
        openssh \
        openssh-client \
        rsync \
        nodejs

 # $REF(默认为' /usr/share/jenkins/ REF / ')包含我们需要的所有引用配置
#设置一个新的安装。使用它来捆绑额外的插件
#或配置文件与您的自定义jenkins Docker镜像。
RUN mkdir -p ${REF}/init.groovy.d

# Jenkins主目录是一个卷，因此配置和构建历史可以持久化，并在映像升级中幸存下来
VOLUME $JENKINS_HOME


ENV JENKINS_UC=https://mirrors.huaweicloud.com/jenkins/
ENV JENKINS_UC_EXPERIMENTAL=https://mirrors.huaweicloud.com/jenkins/updates/experimental/
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"

# for main web interface:
EXPOSE ${http_port}
# will be used by attached slave agents:
EXPOSE ${agent_port}
ENV COPY_REFERENCE_FILE_LOG=$JENKINS_HOME/copy_reference_file.log

# 设置工作目录
WORKDIR ${JENKINS_HOME}

# 运行Jenkins
CMD ["java", "-jar", "/var/jenkins_home/jenkins.war"]